//
//  ShoppingCartCommentTableViewCell.swift
//  OnceNectar
//
//  Created by 法正磊 on 2018/2/7.
//  Copyright © 2018年 com.inwhoop. All rights reserved.
//

import UIKit

class ShoppingCommentTableViewCell: UITableViewCell,AddCornerUIRectCorner {
    
    @IBOutlet weak var bcView: UIView!
    @IBOutlet weak private var headerImageView: BaseCircleImageView!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var levelLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var starView: LCStarRatingView!
    @IBOutlet weak var commentLabel: UILabel!
    @IBOutlet weak var contentLableHeight: NSLayoutConstraint!
    @IBOutlet weak var contentLabelBottom: NSLayoutConstraint!

    @IBOutlet weak var orderTime: UILabel!
    @IBOutlet weak var spec: UILabel!
    @IBOutlet weak var goodsName: UILabel!
    var model:GoodsCommentModel!
    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
    }
    
    func setUI() {
        starView.progress = 0
        starView.starPlaceHolderBorderWidth = 1
        starView.starPlaceHolderBorderColor = UIColor.darkGray
        starView.starPlaceHolderColor = UIColor.white
        starView.enabled = false
        
        addCornerWithView(aView: bcView, aCorners: .allCorners, aSize: CGSize(width: CORNERRADIUS, height: CORNERRADIUS))
    }
    
    func showData(model: GoodsCommentModel) {
        self.model = model
        commentLabel.layoutIfNeeded()
        let path:String = "\(BaseURL)\(model.commentUser?.headIcon! ?? "")"
        
        
        let url = NSURL.init(string: path.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)
        headerImageView.sd_setImage(with: url! as URL, completed: nil)
        
        nameLabel.text = model.commentUser?.nickname!
//        levelLabel.text = "LV.\(model.userInfoModel.level)"
        
        starView.progress = CGFloat(Float(model.predictabilityGrade!)!)
        commentLabel.text = model.commentContent
        contentLableHeight.constant = getContetnHeight(contnet: model.commentContent!)
        if let create = model.created{
            timeLabel.text = create
        }
        goodsName.text = model.goodName
        spec.text = model.specAndCol
        if model.orderTime != "null" {
            let format = DateFormatter()
            format.dateFormat = "yyyy-MM-dd HH:mm:ss"
            let date:Date = format.date(from: (model.orderTime)!)!
            format.dateFormat = "yyyy.MM.dd"
            let dateStr = format.string(from: date)
            orderTime.text = dateStr
        }
        
    }
    
    
    func getContetnHeight(contnet: String) -> CGFloat {
        let contentHeight = contnet.heightWithConstrainedWidth(width: commentLabel.width, height: CGFloat(MAXFLOAT), font: UIFont.systemFont(ofSize: 14)).height + 1
        return contentHeight
    }
    
}
